import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/index',
    name: 'Index',
    component: Home,
    children: [
        {
          path: 'seller',
          component: () => import('../views/SellerList.vue')
        },
        {
          path: 'admin',
          component: () => import('../views/AdminList.vue')
        },
        {
          path: 'product',
          component: () => import('../views/ProductList.vue')
        },
        {
          path: 'reset',
          component: () => import('../views/ResetPass.vue')
        },
    ]
  },
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫
router.beforeEach((to, from, next)=>{
	console.log("to="+to.path)
	console.log("from="+from.path)
	// to 要访问的路径
	// from 从哪个页面而来
	// next 是一个函数,表示放行
	// next() 放行, next('/Login')强制跳转
	// if(to.path === '/login') return next()
	// if(to.path === '/regist') return next()
    
	// 获取登录的状态
	// let token = window.sessionStorage.getItem("token")
	// if(!token) {
	// 	return next({path:'/login'})
	// }

	next()
})

export default router
